# -*- coding: utf-8 -*-
import logging
import os

from django.core.management.base import BaseCommand

from novel.book_robot import Net99libEbookRobot

log = logging.getLogger('asm.gushiwen')


class Command(BaseCommand):
    help = 'fetch the specified book from www.99lib.net'

    def add_arguments(self, parser):
        parser.add_argument('--start', type=int, default=1,
                            help='start page num')
        parser.add_argument('--end', type=int, default=3, help='end page num')
        # parser.add_argument('--c', type=int, default=0,
        #                     help='concurrent workers count(default cpu core count)')        
        parser.add_argument('--m', type=str, default='thread',
                            help='thread or process')
        parser.add_argument('--cache', type=str, default='file',
                            help='cache provider(default,file,database)')        
        parser.add_argument('--site', type=str, default='hetushu',
                            help='search site(99lib[9] or hetushu[h] '
                            'or csw[w])')
        parser.add_argument('--book_id', nargs='+', type=int)
        parser.add_argument('--target', type=str, default='epub',
                            help='target (epub,db,md,txt) ')
        parser.add_argument('--allow_redirects', type=bool,default='False',help='allow_redirects (False,True)')

    def handle(self, *args, **options):
        robot = Net99libEbookRobot()
        robot.execute(options)
